/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainFrame.java
 *
 * Created on 05-Mar-2010, 15:20:03
 */

package phd.dupenois.changeidentifiers.shapedifferences.frames;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import phd.dupenois.changeidentifiers.footprints.Footprint;
import phd.dupenois.changeidentifiers.shapedifferences.SymmetricAreaDifference;
import uk.co.dupenois.geometry.Coordinate;

/**
 *
 * @author mpd209
 */
public class MainFrame extends javax.swing.JFrame implements GridListener{
    private Grid grid;
    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
        Dimension dimension = new Dimension(800, 600);
        setSize(this, dimension);
        grid = new Grid(this, this, 5);
    }
   
    private void setSize(Component component, Dimension dimension){
        component.setSize(dimension);
        component.setPreferredSize(dimension);
        component.setMaximumSize(dimension);
        component.setMinimumSize(dimension);
    }

    public void setGeneralPath1(GeneralPath generalPath){
        this.grid.setGeneralPath1(generalPath);
    }
    public void setGeneralPath2(GeneralPath generalPath){
        this.grid.setGeneralPath2(generalPath);
    }
    public void setArea(Area area){
        this.grid.setArea(area);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        leftPanel = new javax.swing.JPanel();
        topGridPanel = new javax.swing.JPanel();
        timeStepPanel = new javax.swing.JPanel();
        timeStepSlider = new javax.swing.JSlider();
        timeStepTextField = new javax.swing.JTextField();
        bottomGridPanel = new javax.swing.JPanel();
        rightPanel = new javax.swing.JPanel();
        testSelectionPanel = new javax.swing.JPanel();
        testSelectionScrollPane = new javax.swing.JScrollPane();
        testSelectionList = new javax.swing.JList();
        testStepDetailsPanel = new javax.swing.JPanel();
        testStepTimeLabel = new javax.swing.JLabel();
        testStepTimeWithoutCILabel = new javax.swing.JLabel();
        timeStepAlgorithmTimeTakenLabel = new javax.swing.JLabel();
        timeStepSymmetricAreaDifferenceLabel = new javax.swing.JLabel();
        timeStepTimeTakenTextField = new javax.swing.JTextField();
        timeStepTimeTakenWithoutCITextField = new javax.swing.JTextField();
        timeStepAlgorithmTimeTakenTextField = new javax.swing.JTextField();
        timeStepSymmetricAreaDifferenceTextField = new javax.swing.JTextField();
        testDetailsPanel = new javax.swing.JPanel();
        testTimeLabel = new javax.swing.JLabel();
        testTimeWithoutCILabel = new javax.swing.JLabel();
        testFootprintAlgorithm = new javax.swing.JLabel();
        testTimeTakenTextField = new javax.swing.JTextField();
        testTimeWithoutCITextField = new javax.swing.JTextField();
        testFootprintAlgorithmField = new javax.swing.JTextField();
        testTitleLabel = new javax.swing.JLabel();
        testDescriptionScrollPane = new javax.swing.JScrollPane();
        testDescriptionTextArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        leftPanel.setLayout(new java.awt.GridBagLayout());

        topGridPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("With Change Identifiers"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        leftPanel.add(topGridPanel, gridBagConstraints);

        timeStepPanel.setLayout(new java.awt.GridBagLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        timeStepPanel.add(timeStepSlider, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        timeStepPanel.add(timeStepTextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        leftPanel.add(timeStepPanel, gridBagConstraints);

        bottomGridPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("No Change Identifiers"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        leftPanel.add(bottomGridPanel, gridBagConstraints);

        getContentPane().add(leftPanel);

        rightPanel.setLayout(new java.awt.GridBagLayout());

        testSelectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Tests"));
        testSelectionPanel.setLayout(new java.awt.GridLayout());

        testSelectionList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        testSelectionScrollPane.setViewportView(testSelectionList);

        testSelectionPanel.add(testSelectionScrollPane);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightPanel.add(testSelectionPanel, gridBagConstraints);

        testStepDetailsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Test Step Details"));
        testStepDetailsPanel.setLayout(new java.awt.GridBagLayout());

        testStepTimeLabel.setText("Time Taken:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testStepDetailsPanel.add(testStepTimeLabel, gridBagConstraints);

        testStepTimeWithoutCILabel.setText("Time Taken Without CIs:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testStepDetailsPanel.add(testStepTimeWithoutCILabel, gridBagConstraints);

        timeStepAlgorithmTimeTakenLabel.setText("Algorithm Time:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testStepDetailsPanel.add(timeStepAlgorithmTimeTakenLabel, gridBagConstraints);

        timeStepSymmetricAreaDifferenceLabel.setText("Symmetric Area Diff.:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testStepDetailsPanel.add(timeStepSymmetricAreaDifferenceLabel, gridBagConstraints);

        timeStepTimeTakenTextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.7;
        testStepDetailsPanel.add(timeStepTimeTakenTextField, gridBagConstraints);

        timeStepTimeTakenWithoutCITextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.7;
        testStepDetailsPanel.add(timeStepTimeTakenWithoutCITextField, gridBagConstraints);

        timeStepAlgorithmTimeTakenTextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.7;
        testStepDetailsPanel.add(timeStepAlgorithmTimeTakenTextField, gridBagConstraints);

        timeStepSymmetricAreaDifferenceTextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.7;
        testStepDetailsPanel.add(timeStepSymmetricAreaDifferenceTextField, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightPanel.add(testStepDetailsPanel, gridBagConstraints);

        testDetailsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Test Details"));
        testDetailsPanel.setLayout(new java.awt.GridBagLayout());

        testTimeLabel.setText("Time Taken:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testDetailsPanel.add(testTimeLabel, gridBagConstraints);

        testTimeWithoutCILabel.setText("Time Taken Without CIs:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testDetailsPanel.add(testTimeWithoutCILabel, gridBagConstraints);

        testFootprintAlgorithm.setText("Footprint Algorithm:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 0.3;
        testDetailsPanel.add(testFootprintAlgorithm, gridBagConstraints);

        testTimeTakenTextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.7;
        testDetailsPanel.add(testTimeTakenTextField, gridBagConstraints);

        testTimeWithoutCITextField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.7;
        testDetailsPanel.add(testTimeWithoutCITextField, gridBagConstraints);

        testFootprintAlgorithmField.setEditable(false);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 0.7;
        testDetailsPanel.add(testFootprintAlgorithmField, gridBagConstraints);

        testTitleLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        testTitleLabel.setText("[Test Title]");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.weightx = 0.3;
        testDetailsPanel.add(testTitleLabel, gridBagConstraints);

        testDescriptionTextArea.setColumns(20);
        testDescriptionTextArea.setEditable(false);
        testDescriptionTextArea.setRows(5);
        testDescriptionScrollPane.setViewportView(testDescriptionTextArea);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        testDetailsPanel.add(testDescriptionScrollPane, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        rightPanel.add(testDetailsPanel, gridBagConstraints);

        getContentPane().add(rightPanel);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                MainFrame frame = new MainFrame();
                frame.setVisible(true);
                SymmetricAreaDifference diff = new SymmetricAreaDifference(frame);
                Footprint footprint1 = new Footprint();
                footprint1.addLine(new Coordinate(0, 0), new Coordinate(0, 20));
                footprint1.addLine(new Coordinate(0, 20), new Coordinate(20, 20));
                footprint1.addLine(new Coordinate(20, 20), new Coordinate(20, 0));
                footprint1.addLine(new Coordinate(20, 0), new Coordinate(0, 0));
                System.out.println("Footprint 1: "+footprint1.getArea());
                Footprint footprint2 = new Footprint();
                footprint2.addLine(new Coordinate(10, 10), new Coordinate(10, 30));
                footprint2.addLine(new Coordinate(10, 30), new Coordinate(30, 30));
                footprint2.addLine(new Coordinate(30, 30), new Coordinate(30, 10));
                footprint2.addLine(new Coordinate(30, 10), new Coordinate(10, 10));
//                System.out.println("Footprint 2: "+footprint2.getArea());

                double difference = diff.getDifference(footprint1, footprint2);
//                System.out.println("Area Difference: "+difference);
            }
        });
    }

    public void updateLocation(int x, int y) {
    }

    public void setStatus(String status) {
    }

    public Point[] getPoints(int index) {
        return new Point[0];
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bottomGridPanel;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel rightPanel;
    private javax.swing.JScrollPane testDescriptionScrollPane;
    private javax.swing.JTextArea testDescriptionTextArea;
    private javax.swing.JPanel testDetailsPanel;
    private javax.swing.JLabel testFootprintAlgorithm;
    private javax.swing.JTextField testFootprintAlgorithmField;
    private javax.swing.JList testSelectionList;
    private javax.swing.JPanel testSelectionPanel;
    private javax.swing.JScrollPane testSelectionScrollPane;
    private javax.swing.JPanel testStepDetailsPanel;
    private javax.swing.JLabel testStepTimeLabel;
    private javax.swing.JLabel testStepTimeWithoutCILabel;
    private javax.swing.JLabel testTimeLabel;
    private javax.swing.JTextField testTimeTakenTextField;
    private javax.swing.JLabel testTimeWithoutCILabel;
    private javax.swing.JTextField testTimeWithoutCITextField;
    private javax.swing.JLabel testTitleLabel;
    private javax.swing.JLabel timeStepAlgorithmTimeTakenLabel;
    private javax.swing.JTextField timeStepAlgorithmTimeTakenTextField;
    private javax.swing.JPanel timeStepPanel;
    private javax.swing.JSlider timeStepSlider;
    private javax.swing.JLabel timeStepSymmetricAreaDifferenceLabel;
    private javax.swing.JTextField timeStepSymmetricAreaDifferenceTextField;
    private javax.swing.JTextField timeStepTextField;
    private javax.swing.JTextField timeStepTimeTakenTextField;
    private javax.swing.JTextField timeStepTimeTakenWithoutCITextField;
    private javax.swing.JPanel topGridPanel;
    // End of variables declaration//GEN-END:variables

}
